<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<script type="text/javascript">
	var form_url = base.contextPath+"/sysmgr/area/add.do" ; 
	var area_treebox, area_typebox ;
	$(function() {
		area_treebox = $("#area_treebox").combotree({
			url: base.contextPath+"/sysmgr/area/treegrid_areas.do",
			idField: 'id', treeField: 'areaName',parentField: 'parentAreaId'
	    });  
		$("#area_typebox").combobox({
			valueField: 'label', textField: 'value', value: '国家',
			data: [
			       { label: '国家', value: '国家' },{ label: '省份', value: '省份' },
			       { label: '直辖市', value: '直辖市' },{ label: '地市', value: '地市' },
			       { label: '区县', value: '区县' }
			],
			panelHeight:'auto', editable:false, autoShowPanel: true
	    });
		//编辑，加载表单数据
		if($('input[name=id]').val().length > 0) {
			form_url = base.contextPath+"/sysmgr/area/edit.do" ;
			$.post(base.contextPath+"/sysmgr/area/get.do", {id:$('input[name=id]').val()}, function(result) {
				if (result.id != undefined) {
					$('form').form('load', {
						'id' : result.id,
						'areaName' : result.areaName,
						'areaType' : result.areaType,
						'parentAreaId' : result.parentAreaId,
						'countryCode' : result.countryCode,
						'areaNumber' : result.areaNumber,
						'areaCode' : result.areaCode,
						'remark' : result.remark
					});
				}
			}, 'json');
		}
	});
	
	//提交表单数据
	var submitNow = function($d, $tg) {
		$.post(form_url, $("#form").form("getData"), function(result) {
			if (result.status) {
				$tg.treegrid("reload");$d.dialog("close") ;
				$.easyui.loaded();alertify.success(result.msg);
			} else {
				$.easyui.loaded();alertify.error(result.msg);
			}
		}, 'json').error(function(){$.easyui.loaded();});
	};
	
	//验证表单
	var submitForm = function($d, $tg) {
		if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $tg) ; ;
		} 
	};
</script>
<form id="form" class="easyui-form form_container">
	<input type="hidden" name="id" value="${id}" />
	<table class="tableform">
		<tr>
			<th>区域名称：</th>
			<td><input name="areaName" class="easyui-validatebox" type="text" data-options="required: true, prompt: '区域名称'" /></td>
		</tr>
		<tr>
			<th>区域类型：</th>
			<td><input id="area_typebox" name="areaType" style="width:218px;height:30px;" /></td>
		</tr>
		<tr>	
			<th>上级区域：</th>
			<td><input id="area_treebox" name="parentAreaId" style="width:218px;height:30px;" /><a onClick="area_treebox.combotree('setValue','');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_clear'"></a></td>
		</tr>
		<tr>
			<th>国家代码：</th>
			<td><input name="countryCode" class="easyui-validatebox" type="text" data-options="required: true" /></td>
		</tr>
		<tr>
			<th>区域区号：</th>
			<td><input name="areaNumber" class="easyui-validatebox" type="text" data-options="required: true" /></td>
		</tr>
		<tr>
			<th>备注：</th>
			<td colspan="3">
				<textarea name="remark" rows="5" cols="5" style="border:1px solid #A5AEB6;width:489px;height:85px;max-width:489px;min-width:489px;max-height:85px;min-height:85px;"></textarea>
			</td>
		</tr>
	</table>
</form>
